<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <button>sesssionStorage存储</button>
    <button>sesssionStorage获取</button>
    <button>sesssionStorage更新</button>
    <button>sesssionStorage删除</button>
    <button>sesssionStorage清除</button>
    <script>
         var txt = document.querySelector('input');
         var btns = document.querySelectorAll('button');
         btns[0].onclick = function(){
            alert('存储成功');
            window.sessionStorage.setItem('userName',txt.value);
            window.sessionStorage.setItem('pwd','1111');
            window.sessionStorage.setItem('age',20);
         }

         btns[1].onclick = function(){
            alert('获取成功');
            txt.value = window.sessionStorage.getItem('userName');
         }

         btns[2].onclick = function(){
            alert('更新成功');
            window.sessionStorage.setItem('userName', txt.value);
         }

         btns[3].onclick = function(){
            alert('删除成功');
            window.sessionStorage.removeItem('userName');
         }
         //        sessionStorage清空数据
        btns[4].onclick = function () {
             alert('清楚成功');
            window.sessionStorage.clear();
        }
    </script>
</body>
</html>